home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Programming / QuakeTools / src / libqtools / bsp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-29  |  7.1 KB  |  273 lines

  1. #ifndef    BSP_H
  2. #define    BSP_H
  3. /*
  4.  * ============================================================================
  5.  * structures
  6.  * ============================================================================
  7.  */
  8.  
  9. /* upper design bounds */
  10. #define    MAX_MAP_HULLS        4
  11. #define    MAX_HULL_POINTS        32
  12. #define    MAX_HULL_EDGES        64
  13.  
  14. #define BSP_VERSION        29
  15.  
  16. struct dmodel_t {
  17.   float mins[3], maxs[3];
  18.   float origin[3];
  19.   int headnode[MAX_MAP_HULLS];
  20.   /* not including the solid leaf 0 */
  21.   int visleafs;
  22.   int firstface, numfaces;
  23. };
  24.  
  25. struct dmiptexlump_t {
  26.   int nummiptex;
  27.   /* [nummiptex] */
  28.   int dataofs[4];
  29. };
  30.  
  31. struct dvertex_t {
  32.   float point[3];
  33. };
  34.  
  35. /* 0-2 are axial planes */
  36. #define    PLANE_X            0
  37. #define    PLANE_Y            1
  38. #define    PLANE_Z            2
  39.  
  40. /* 3-5 are non-axial planes snapped to the nearest */
  41. #define    PLANE_ANYX        3
  42. #define    PLANE_ANYY        4
  43. #define    PLANE_ANYZ        5
  44.  
  45. struct dplane_t {
  46.   float normal[3];
  47.   float dist;
  48.   /* PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate */
  49.   int type;
  50. };
  51.  
  52. #define    CONTENTS_EMPTY        -1
  53. #define    CONTENTS_SOLID        -2
  54. #define    CONTENTS_WATER        -3
  55. #define    CONTENTS_SLIME        -4
  56. #define    CONTENTS_LAVA        -5
  57. #define    CONTENTS_SKY        -6
  58.  
  59. struct dnode_t {
  60.   int planenum;
  61.   /* negative numbers are -(leafs+1), not nodes */
  62.   short int children[2];
  63.   /* for sphere culling */
  64.   short int mins[3];
  65.   short int maxs[3];
  66.   unsigned short int firstface;
  67.   /* counting both sides */
  68.   unsigned short int numfaces;
  69. };
  70.  
  71. struct dclipnode_t {
  72.   int planenum;
  73.   /* negative numbers are contents */
  74.   short int children[2];
  75. };
  76.  
  77. struct texinfo {
  78.   /* [s/t][xyz offset] */
  79.   float vecs[2][4];
  80.   int miptex;
  81.   int flags;
  82. };
  83.  
  84. /* sky or slime, no lightmap or 256 subdivision */
  85. #define    TEX_SPECIAL        (1<<0)    /* aequivalent to 1 */
  86. /* extensions to bsp-type added by niels */
  87. #define    TEX_WATER        (1<<1)
  88. #define    TEX_SLIME        (1<<2)
  89. #define    TEX_LAVA        (1<<3)
  90. #define    TEX_SKY            (1<<4)
  91.  
  92. /*
  93.  * note that edge 0 is never used, because negative edge nums are used for
  94.  * counterclockwise use of the edge in a face
  95.  */
  96. struct dedge_t {
  97.   /* vertex numbers */
  98.   unsigned short int v[2];
  99. };
  100.  
  101. #define    MAXLIGHTMAPS        4
  102. struct dface_t {
  103.   short int planenum;
  104.   short int side;
  105.   /* we must support > 64k edges */
  106.   int firstedge;
  107.   short int numedges;
  108.   short int texinfo;
  109.   /* lighting info */
  110.   unsigned char styles[MAXLIGHTMAPS];
  111.   /* start of [numstyles*surfsize] samples */
  112.   int lightofs;
  113. };
  114.  
  115. #define    AMBIENT_WATER        0
  116. #define    AMBIENT_SKY        1
  117. #define    AMBIENT_SLIME        2
  118. #define    AMBIENT_LAVA        3
  119.  
  120. /* automatic ambient sounds */
  121. #define    NUM_AMBIENTS        4
  122.  
  123. /*
  124.  * leaf 0 is the generic CONTENTS_SOLID leaf, used for all solid areas
  125.  * all other leafs need visibility info
  126.  */
  127. struct dleaf_t {
  128.   int contents;
  129.   /* -1 = no visibility info */
  130.   int visofs;
  131.   /* for frustum culling */
  132.   short int mins[3];
  133.   short int maxs[3];
  134.   unsigned short int firstmarksurface;
  135.   unsigned short int nummarksurfaces;
  136.   unsigned char ambient_level[NUM_AMBIENTS];
  137. };
  138.  
  139. struct dpair {
  140.   int offset, size;
  141. };
  142.  
  143. struct bspheader {
  144.   int version;
  145.   struct dpair entities, planes, miptex, vertices, visilist
  146.    ,nodes, texinfo, faces, lightmaps, clipnodes
  147.    ,leaves, lface, edges, ledges, models;
  148. };
  149.  
  150. struct visdata {
  151.   char procName[32];
  152.   int size;
  153. };
  154.  
  155. /*
  156.  * ============================================================================
  157.  * bsp-tree related
  158.  * ============================================================================
  159.  */
  160.  
  161. // the exact bounding box of the brushes is expanded some for the headnode
  162. // volume.  is this still needed?
  163. #define    SIDESPACE            24
  164.  
  165. #define ON_EPSILON            0.05
  166. #define    POINT_EPSILON            0.01
  167. #define    DISTEPSILON            0.01
  168. #define    T_EPSILON            0.01
  169. #define    ZERO_EPSILON            0.001
  170. #define CONTINUOUS_EPSILON        0.001
  171. #define    ANGLEEPSILON            0.00001
  172.  
  173. #define BOGUS_RANGE            18000
  174.  
  175. #ifdef DYNAMIC_EDGES
  176. struct visfacet {
  177.   struct visfacet *next;
  178.   int planenum;
  179.   int planeside;                                   // which side is the front of the face
  180.   int texturenum;
  181.   int contents[2];                                   // 0 = front side
  182.   struct visfacet *original;                               // face on node
  183.   int outputnumber;                                   // only valid for original faces after
  184.   // write surfaces
  185.   short int numpoints;
  186.   vec3_t *pts;                                       // FIXME: change to use winding_t
  187.   int *edges;
  188. } __packed;                // 36 + 384 + 128 = 548
  189. #else
  190. struct visfacet {
  191.   struct visfacet *next;
  192.   int planenum;
  193.   int planeside;                                   // which side is the front of the face
  194.   int texturenum;
  195.   int contents[2];                                   // 0 = front side
  196.   struct visfacet *original;                               // face on node
  197.   int outputnumber;                                   // only valid for original faces after
  198.   // write surfaces
  199.   //int numpoints;
  200.   short int numpoints;                                   // maximum is MAXEDGES
  201.   vec3_t pts[MAXEDGES];                                   // FIXME: change to use winding_t
  202.   int edges[MAXEDGES];
  203. } __packed;                // 36 + 384 + 128 = 548
  204.                     // 34 + 120 +  36 = 190
  205. #endif
  206.  
  207. struct surface {
  208.   struct surface *next;
  209.   struct surface *original;                               // before BSP cuts it up
  210.   int planenum;
  211.   int outputplanenum;                                   // only valid after WriteSurfacePlanes
  212.   vec3_t mins, maxs;
  213.   bool onnode;                                           // true if surface has already been used
  214.   // as a splitting node
  215.   struct visfacet *faces;                               // links to all the faces on either side of the surf
  216. } __packed;                // 48
  217.  
  218. //
  219. // there is a node_t structure for every node and leaf in the bsp tree
  220. //
  221. #define    PLANENUM_LEAF            -1
  222.  
  223. struct node {
  224.   vec3_t mins, maxs;                                   // bounding volume, not just points inside
  225. // information for decision nodes
  226.   int planenum;                                       // -1 = leaf node
  227.   int outputplanenum;                                   // only valid after WriteNodePlanes
  228.   int firstface;                                   // decision node only
  229.   int numfaces;                                       // decision node only
  230.   struct node *children[2];                               // only valid for decision nodes
  231.   struct visfacet *faces;                               // decision nodes only, list for both sides
  232. // information for leafs
  233.   int contents;                                       // leaf nodes (0 for decision nodes)
  234.   struct visfacet **markfaces;                               // leaf nodes only, point to node faces
  235.   struct portal *portals;
  236.   int visleafnum;                                   // -1 = solid
  237.   int valid;                                       // for flood filling
  238.   //int occupied;                                   // light number in leaf for outside filling
  239.   short int occupied;                                   // maximum in number of entities
  240. } __packed;                // 76
  241.                     // 74
  242.  
  243. /*
  244.  * ============================================================================
  245.  * globals
  246.  * ============================================================================
  247.  */
  248.  
  249. /* light */
  250. extern bool waterlit;
  251. extern float scale, range;
  252. /* qbsp */
  253. extern bool watervis, slimevis;
  254. extern bool nofill, notjunc, noclip, onlyents, usehulls;
  255. extern int subdivide, hullnum;
  256. /* vis */
  257. extern bool fastvis;
  258. extern int vislevel;
  259.  
  260. /*
  261.  * ============================================================================
  262.  * prototypes
  263.  * ============================================================================
  264.  */
  265.  
  266. #include "memory.h"
  267.  
  268. bool AddBSP(struct palpic *inPic, struct rawdata *inData, char *bspName, operation procOper, filetype inType);
  269. bool ExtractBSP(FILE *file, FILE *script, char *destDir, char *entryName, filetype outType, operation procOper, bool recurse);
  270. struct memory *LoadBSP(FILE *bspFile, int availLoad);
  271. void WriteBSP(FILE *bspFile, __memBase);
  272. #endif
  273.